package com.olddriver.crm.service.impl;


import com.olddriver.crm.domain.CompensationDetails;
import com.olddriver.crm.mapper.CompensationDetailsMapper;
import com.olddriver.crm.mapper.CompensationMapper;
import com.olddriver.crm.mapper.PaidListMapper;
import com.olddriver.crm.mapper.TotalInfoMapper;
import com.olddriver.crm.page.PageResult;
import com.olddriver.crm.query.QueryObject;
import com.olddriver.crm.service.ICompensationDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class CompensationDetailsServiceImpl implements ICompensationDetailsService {

    @Autowired
    private CompensationDetailsMapper detailsMapper;

    @Autowired
    private PaidListMapper paidListMapper;

    @Autowired
    private TotalInfoMapper totalInfoMapper;
    @Autowired
    private CompensationMapper compensationMapper;


    @Override
    public void deleteByPrimaryKey(Long id) {
        detailsMapper.deleteByPrimaryKey(id);

    }

    @Override
    public void insert(CompensationDetails record, String sn ) {
        detailsMapper.insert(record);
        totalInfoMapper.updateTotalFee(record.getTotalFee(),record.getSn());
        compensationMapper.updateTotalFee(record.getTotalFee(),record.getSn());
    }

    @Override
    public CompensationDetails selectByPrimaryKey(Long id) {
        CompensationDetails claim = detailsMapper.selectByPrimaryKey(id);
        return claim;
    }

    @Override
    public List<CompensationDetails> selectAll() {
        List<CompensationDetails> compensationDetails = detailsMapper.selectAll();
        return compensationDetails;
    }

    @Override
    public void updateByPrimaryKey(CompensationDetails record) {

        detailsMapper.updateByPrimaryKey(record);
    }

    @Override
    public CompensationDetails selectDetailBySn(String sn) {
        CompensationDetails details = detailsMapper.selectDetailBySn(sn);
        return details;
    }

    @Override
    public PageResult query(QueryObject qo) {
        int total = detailsMapper.queryTotal(qo);
        if (total == 0) {
            return new PageResult(total, Collections.emptyList());
        }
        return new PageResult(total, detailsMapper.queryRows(qo));
    }



}




